package top.wilbert.collegelink.message.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.wilbert.collegelink.message.dao.ChatListDao;
import top.wilbert.collegelink.message.entity.ChatListEntity;
import top.wilbert.collegelink.message.service.ChatListService;

import java.util.List;

/**
 * @Description:
 * @Author:Jiiangyu
 * @CreatTime:2023-02-27-19:48
 */
@Service("ChatListService")
public class ChatListServiceImpl extends ServiceImpl<ChatListDao, ChatListEntity> implements ChatListService {
    @Override
    public List<ChatListEntity> getChatListByFromUser(String fromName) {
        QueryWrapper<ChatListEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("from_user", fromName);
        queryWrapper.eq("status", 1);

        List<ChatListEntity> list = this.baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public void updateListByLinkId(Long linkId) {
        ChatListEntity chatListEntity = new ChatListEntity();
        chatListEntity.setFromWindow(true);
        chatListEntity.setUnread(0L);

        QueryWrapper<ChatListEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("link_id", linkId);

        this.baseMapper.update(chatListEntity, queryWrapper);
    }
}
